﻿// Decompiled with JetBrains decompiler
// Type: MCM.Abstractions.Base.PerCampaign.ExternalPerCampaignSettings
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using MCM.Abstractions.FluentBuilder;
using MCM.Abstractions.Utils;
using MCM.Abstractions.Xml;
using MCM.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;

#nullable enable
namespace MCM.Abstractions.Base.PerCampaign
{
  public sealed class ExternalPerCampaignSettings : FluentPerCampaignSettings
  {
    public static ExternalPerCampaignSettings? CreateFromXmlStream(
      Stream xmlStream,
      Func<IPropertyDefinitionBase, IRef> assignRefDelegate,
      PropertyChangedEventHandler? propertyChanged = null)
    {
      SettingsXmlModel settingsXmlModel = SerializationUtils.DeserializeXml<SettingsXmlModel>(xmlStream);
      if (settingsXmlModel == null)
        return (ExternalPerCampaignSettings) null;
      char subGroupDelimiter = settingsXmlModel.SubGroupDelimiter[0];
      IEnumerable<SettingsPropertyDefinition> settingsPropertyDefinitions = settingsXmlModel.Groups.SelectMany<PropertyGroupXmlModel, SettingsPropertyDefinition>((Func<PropertyGroupXmlModel, IEnumerable<SettingsPropertyDefinition>>) (g => g.Properties.Select<PropertyBaseXmlModel, SettingsPropertyDefinition>((Func<PropertyBaseXmlModel, SettingsPropertyDefinition>) (p => new SettingsPropertyDefinition(SettingsUtils.GetPropertyDefinitionWrappers((object) p), (IPropertyGroupDefinition) g, assignRefDelegate((IPropertyDefinitionBase) p), subGroupDelimiter))))).Concat<SettingsPropertyDefinition>(settingsXmlModel.Properties.Select<PropertyBaseXmlModel, SettingsPropertyDefinition>((Func<PropertyBaseXmlModel, SettingsPropertyDefinition>) (p => new SettingsPropertyDefinition(SettingsUtils.GetPropertyDefinitionWrappers((object) p), SettingsPropertyGroupDefinition.DefaultGroup, assignRefDelegate((IPropertyDefinitionBase) p), subGroupDelimiter))));
      List<SettingsPropertyGroupDefinition> settingsPropertyGroups = SettingsUtils.GetSettingsPropertyGroups(subGroupDelimiter, (IEnumerable<ISettingsPropertyDefinition>) settingsPropertyDefinitions);
      return new ExternalPerCampaignSettings(settingsXmlModel.Id, settingsXmlModel.DisplayName, settingsXmlModel.FolderName, settingsXmlModel.SubFolder, settingsXmlModel.UIVersion, subGroupDelimiter, propertyChanged, (IEnumerable<SettingsPropertyGroupDefinition>) settingsPropertyGroups, (IEnumerable<ISettingsPresetBuilder>) new List<ISettingsPresetBuilder>());
    }

    private ExternalPerCampaignSettings(
      string id,
      string displayName,
      string folderName,
      string subFolder,
      int uiVersion,
      char subGroupDelimiter,
      PropertyChangedEventHandler? onPropertyChanged,
      IEnumerable<SettingsPropertyGroupDefinition> settingPropertyGroups,
      IEnumerable<ISettingsPresetBuilder> presets)
      : base(id, displayName, folderName, subFolder, uiVersion, subGroupDelimiter, onPropertyChanged, settingPropertyGroups, presets)
    {
    }
  }
}
